package com.fandou.airobot.ui.recording;

import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.CheckBox;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;

import com.blankj.utilcode.util.BarUtils;
import com.fandou.airobot.R;
import com.fandou.videocreator.encoder.AvcEncoder;
import com.lxj.xpopup.core.CenterPopupView;

import java.io.File;
import java.util.List;

/**
 * @author Jm
 * @date 2020/7/9 14:17
 * @description 记录模式退出时候的操作pop
 */
public class RecordingExitTipPop extends CenterPopupView implements LifecycleObserver {

    private Context mContext;

    @Override
    protected int getImplLayoutId() {
        return R.layout.ai_robot_recording_exit_tip_pop;
    }

    public RecordingExitTipPop(@NonNull Context context, OnExitListener onExitListener) {
        super(context);
        mContext = context;
        this.onExitListener = onExitListener;
        if (context instanceof AppCompatActivity) {
            ((AppCompatActivity) context).getLifecycle().addObserver(this);
            Window window = ((AppCompatActivity) mContext).getWindow();
            BarUtils.setStatusBarVisibility(window, false);
            BarUtils.setNavBarVisibility(window, false);
//
//            Window window = ((AppCompatActivity) mContext).getWindow();
//            window.setStatusBarColor(getResources().getColor(android.R.color.transparent));
//            View decorView = window.getDecorView();
//            decorView.setSystemUiVisibility(
//                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
//                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
//                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
//                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
//                            | View.SYSTEM_UI_FLAG_FULLSCREEN
//                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
    }

    @Override
    protected void onCreate() {
        super.onCreate();

        CheckBox cbSave = findViewById(R.id.cbSave);
        CheckBox cbSend = findViewById(R.id.cbSend);


        findViewById(R.id.csbCancel).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });


        //exit
        findViewById(R.id.csbExit).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                if (cbSave.isChecked()) {
                    //保存记录
                }

                if (cbSend.isChecked()) {
                    // TODO: 2020/7/9
                    //执行将当前记录发送给老师/家长
                }

                onExitListener.onExitRecording(cbSave.isChecked(),cbSend.isChecked());
                dismiss();
            }
        });
    }

//    /**
//     * @param paths      照片文件路径（本地路径）
//     * @param delay      每张照片的持续时间（秒）
//     * @param targetPath 视频文件路径
//     * @param size       长度为2的数组，设置视频的分辨率: size[0]是宽，size[1]是高
//     */
//    public static boolean imageToVideo(List<String> paths, int delay, String targetPath, int[] size) {
//        if (!paths.isEmpty()) {
//            BitmapProvider bitmapProvider = new BitmapProvider(paths, size);
//            bitmapProvider.init();
//            if (!bitmapProvider.isAvailable()) {
//                return false;
//            }
//            new AvcEncoder(bitmapProvider, 1f / delay, new File(targetPath), 0, null).start();
//            return true;
//        }
//        return false;
//    }


    @Override
    protected void onShow() {

        if (mContext instanceof AppCompatActivity) {
            Window window = ((AppCompatActivity) mContext).getWindow();
            BarUtils.setStatusBarVisibility(window, false);
            BarUtils.setNavBarVisibility(window, false);

//            window.setStatusBarColor(getResources().getColor(android.R.color.transparent));
//            View decorView = window.getDecorView();
//            decorView.setSystemUiVisibility(
//                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
//                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
//                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
//                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
//                            | View.SYSTEM_UI_FLAG_FULLSCREEN
//                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
        super.onShow();
    }

    private OnExitListener onExitListener;

    public interface OnExitListener {
        void onExitRecording(boolean isSave, boolean isSend);
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    @Override
    protected void onDismiss() {
        super.onDismiss();

    }
}
